//
//  STOrderListVC.m
//  YiYueStore
//
//  Created by zhouzhouzhou on 2018/10/22.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STOrderListVC.h"
#import "STOrderListView.h"
#import "STOrderDetailVC.h"
@interface STOrderListVC ()<STOrderListViewDelegate>{
    STOrderListView * listView;
    NSInteger _page;
}
@property(strong ,nonatomic)NSMutableArray * dataArray;
@property (nonatomic,assign)NSInteger selType;//页面订单类型
@end

@implementation STOrderListVC
-(instancetype)initWithType:(NSInteger)type{
    if (self = [super init]) {
        _selType = type;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setOrderListView];
}


-(void)setOrderListView{
    _dataArray = [[NSMutableArray alloc] init];
    [self loadListView];
    [self loadListDataWithIsHead:YES];
}

//加载数据
-(void)loadListDataWithIsHead:(BOOL)isHead{
    if (isHead) {
        _page = 1;
    }else{
        _page++;
    }
    NSString * stylistId = [YLUserInfo sharedInstance].stylistId;
    NSDictionary * params = @{@"page":@(_page),@"size":@(10),@"stylistId":stylistId,@"status":@(_selType+1)};
    BasicRequest * request = [[BasicRequest alloc] initWithParams:params];
    request.URL = [NSString stringWithFormat:@"%@stylistOrder/findOrderPage",BASEURL];
    request.requestMethod = HttpRequestMethodGET;
    request.isShowHUD = NO;
    [request startRequestWithSuccess:^(NSURLSessionTask *task, id responseObject) {
        NSArray * data = [NSArray modelArrayWithClass:[YLHomeOrderListModel class] json:[responseObject objectForKey:@"data"]];
        if (isHead) {
            _dataArray = [[NSMutableArray alloc] initWithArray:data];
        }else{
            [_dataArray addObjectsFromArray:data];
        }
        listView.orderListArr = _dataArray;
        listView.selType = _selType;
        [listView loadOrderListView];
        [listView endRefresh];
    } Failure:^(NSURLSessionTask *task, NSError *error) {
        [listView endRefresh];
    }];
}

- (void)loadListView {
    listView = [[STOrderListView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64-40)];
    listView.orderDelegate = self;
    [listView loadOrderListView];
    [self.view addSubview:listView];
}

//上划加载更多
-(void)orderListViewAddMoreData{
    [self loadListDataWithIsHead:NO];
}

//下拉刷新
-(void)orderListViewLoadNewData{
    [self loadListDataWithIsHead:YES];
}

-(void)orderListViewSelIndexPath:(NSIndexPath *)indexPath{
    STOrderDetailVC * orderDetailVC = [STOrderDetailVC new];
    orderDetailVC.orderType = self.selType;
    orderDetailVC.detailModel = [_dataArray objectAtIndex:indexPath.row];
    orderDetailVC.hidesBottomBarWhenPushed = YES;
    [self.fatherController.navigationController pushViewController:orderDetailVC animated:NO];
    
}


@end
